Creates a C/C++ style structure to be used in DllCall.
DllStructCreate ( "Struct" [,Pointer] )
Parameters
"Struct" | A string representing the structure to create (See Remarks). |
Pointer | If supplied the struct will not allocate memory but use the pointer supplied. |
Return Value
Success: | A variable for use with DllStruct calls. |
Failure: | 0. |
@Error: | 0 = No Error. |
1 = Variable passed to DllStructCreate was not a string. | |
2 = There is an unknown Data Type in the string passed. | |
3 = Failed to allocate the memory needed for the struct, or Pointer = 0. | |
4 = Error allocating memory for the passed string. | |
Remarks
Each data type must be separated by a semi-colon ';'. Create arrays by adding '[size]' after the data type.Type | Details |
byte | 8bit(1byte) signed char |
ubyte | 8bit(1byte) unsigned char |
char | 8bit(1byte) ASCII char |
wchar | 16bit(2byte) Wide char |
short | 16bit(2bytes) signed integer |
ushort | 16bit(2bytes) unsigned integer |
int | 32bit(4bytes) signed integer |
long | 32bit(4bytes) signed integer |
uint | 32bit(4bytes) unsigned integer |
dword | 32bit(4bytes) signed integer |
udword | 32bit(4bytes) unsigned integer |
ptr | 32bit(4bytes) integer |
hwnd | 32bit(4bytes) integer |
float | 32bit(4bytes) floating point |
double | 64bit(8bytes) floating point |
int64 | 64bit(8bytes) signed integer |
uint64 | 64bit(8bytes) unsigned integer |
Related
DllCall, DllStructCreate, DllStructGetData, DllStructSetData, DllStructGetPtr
Example
;=========================================================
; Create the struct
; struct {
; int var1;
; unsigned char var2;
; unsigned int var3;
; char var4[128];
; }
;=========================================================
$str = "int var1;ubyte var2;uint var3;char var4[128]"
$a = DllStructCreate($str)
if @error Then
MsgBox(0,"","Error in DllStructCreate " & @error);
exit
endif
;=========================================================
; Set data in the struct
; struct.var1 = -1;
; struct.var2 = 255;
; struct.var3 = INT_MAX; -1 will be typecasted to (unsigned int)
; strcpy(struct.var4,"Hello");
; struct.var4[0] = 'h';
;=========================================================
DllStructSetData($a,"var1",-1)
DllStructSetData($a,"var2",255)
DllStructSetData($a,"var3",-1)
DllStructSetData($a,"var4","Hello")
DllStructSetData($a,"var4",Asc("h"),1)
;=========================================================
; Display info in the struct
;=========================================================
MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _
"Struct pointer: " & DllStructGetPtr($a) & @CRLF & _
"Data:" & @CRLF & _
DllStructGetData($a,1) & @CRLF & _
DllStructGetData($a,2) & @CRLF & _
DllStructGetData($a,3) & @CRLF & _
DllStructGetData($a,4))
;=========================================================
; Free the memory allocated for the struct if needed
;=========================================================
$a=0